bitkeeper revision 1.1159.212.116 (4208079bssB3TTrruGComoEvhNrq9Q)
authoriap10@labyrinth.cl.cam.ac.uk <iap10@labyrinth.cl.cam.ac.uk>
Tue, 8 Feb 2005 00:28:11 +0000 (00:28 +0000)
committeriap10@labyrinth.cl.cam.ac.uk <iap10@labyrinth.cl.cam.ac.uk>
Tue, 8 Feb 2005 00:28:11 +0000 (00:28 +0000)
Fix some of the time virtualization issues.

- Compute the elapsed time correctly in the cpu loop
- Try to inject interrupts in the vmexit handler

Signed-off-by: Edwin Zhai <edwin.zhai@intel.com>
Signed-off-by: Arun Sharma <arun.sharma@intel.com>
Signed-off-by: ian@xensource.com
tools/ioemu/iodev/cpu.cc
xen/arch/x86/vmx.c

index 17a85539ce3c54335aa460394205139aea655e6c..11e761d7749e42aefb01903c4263d6ae0e4dda60 100644 (file)
@@ -167,6 +167,9 @@ bx_cpu_c::timer_handler(void)
 #define rdtscl(low) \
      __asm__ __volatile__("rdtsc" : "=a" (low) : : "edx")
 
+#define rdtscll(val) \
+     __asm__ __volatile__("rdtsc" : "=A" (val))
+
 void
 bx_cpu_c::cpu_loop(int max_instr_count)
 {
@@ -180,7 +183,8 @@ bx_cpu_c::cpu_loop(int max_instr_count)
        FD_ZERO(&rfds);
 
        while (1) {
-               unsigned long t1, t2;
+                static unsigned long long t1 = 0;
+               unsigned long long t2;
 
                /* Wait up to one seconds. */
                tv.tv_sec = 0;
@@ -188,18 +192,30 @@ bx_cpu_c::cpu_loop(int max_instr_count)
                FD_SET(evtchn_fd, &rfds);
 
                send_event = 0;
-               rdtscl(t1);             
+
+               if (t1 == 0) // the first time
+                       rdtscll(t1);
+
                retval = select(evtchn_fd+1, &rfds, NULL, NULL, &tv);
-               rdtscl(t2);
                if (retval == -1) {
                        perror("select");
                        return;
                }
-               //stime_usec = 1000000 * (1 - tv.tv_sec)  - tv.tv_usec;
-               if (t2 > t1)
-                       BX_TICKN((t2 - t1) / 2000);     // should match ips in bochsrc
+
+               rdtscll(t2);
+
+#if __WORDSIZE == 32
+#define ULONGLONG_MAX   0xffffffffffffffffULL
+#else
+#define ULONGLONG_MAX   ULONG_MAX
+#endif
+
+               if (t2 <= t1)
+                       BX_TICKN((t2 + ULONGLONG_MAX - t1));
                else
-                       BX_TICKN((MAXINT - t1 + t2) / 2000);    // should match ips in bochsrc
+                       BX_TICKN((t2 - t1));
+               t1 = t2;
+
                timer_handler();
                if (BX_CPU_INTR) {
 #if BX_SUPPORT_APIC
@@ -248,7 +264,7 @@ bx_cpu_c::interrupt(Bit8u vector)
        // page.
 
        rdtscl(tscl);
-       BX_INFO(("%lx: injecting vector: %x\n", tscl, vector));
+       BX_DEBUG(("%lx: injecting vector: %x\n", tscl, vector));
        intr = &(((vcpu_iodata_t *) shared_page)->vp_intr[0]);
        set_bit(vector, intr);
        
index 67c08d073fa59de18bbc4a4e26f8b82fbd11d288..486998c34a76ec22979f0925185bc014074106d4 100644 (file)
@@ -927,6 +927,8 @@ asmlinkage void vmx_vmexit_handler(struct xen_regs regs)
     default:
         __vmx_bug(&regs);       /* should not happen */
     }
+
+    vmx_intr_assist(d);
     return;
 }